<template>
  <div class="icons">
    <swiper :swiperOption="swiperOption">
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div class="icon-little" v-for="item of page" :key="item.id" >
          <div class="icon-logo">
            <img class="icon-img" :src="item.imgUrl">
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>
<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data(){
    return{
      swiperOption: {
        autoplay: false
      }
      // iconList: [
      //   {
      //     id: '0001',
      //     imgUrl: '../../../../static/pngs/Flash_camera.png',
      //     desc: '景点门票'
      //   },{
      //     id: '0002',
      //     imgUrl: '../../../../static/pngs/diving_mask.png',
      //     desc: '滑雪季'
      //   },{
      //     id: '0003',
      //     imgUrl: '../../../../static/pngs/flippers.png',
      //     desc: '潜水之旅'
      //   },{
      //     id: '0004',
      //     imgUrl: '../../../../static/pngs/beach.png',
      //     desc: '动植物园'
      //   },{
      //     id: '0005',
      //     imgUrl: '../../../../static/pngs/castle.png',
      //     desc: '一日游'
      //   },{
      //     id: '0006',
      //     imgUrl: '../../../../static/pngs/Fushimi_Inari_Taisha.png',
      //     desc: '必游榜单'
      //   },{
      //     id: '0007',
      //     imgUrl: '../../../../static/pngs/Yacht.png',
      //     desc: '自然风光'
      //   },{
      //     id: '0008',
      //     imgUrl: '../../../../static/pngs/菜单展开.png',
      //     desc: '全部'
      //   },{
      //     id: '0009',
      //     imgUrl: '../../../../static/pngs/菜单展开.png',
      //     desc: '全部'
      //   }
      // ]
    }
  },
  computed: {
    pages(){
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
          pages[page].push(item)
      })
      return pages
    }
  }
}
</script>
<style lang="stylus" scoped>
@import '../../../assets/styles/var.styl';
@import '../../../assets/styles/mixins.styl';

.icons >>> .swiper-container {
  height: 0;
  padding-bottom: 50%;
}

// 加载时占位，防止出现抖动感
// 长宽比2：1
.icons {
  overflow: hidden;
  height: 0;
  padding-bottom: 50%;
  margin-top: 0.1rem;
}

// 长宽比1：1
// padding-bottom对应的就是高度的比例（icon宽度25%， 高度25%，实现了长宽比1：1）
.icon-little {
  position: relative;
  overflow: hidden;
  float: left;
  width: 25%;
  height: 0;
  padding-bottom: 25%;
}

.icon-logo {
  position: absolute;
  top: 0.2rem;
  left: 0;
  right: 0;
  bottom: 0.34rem;
  box-sizing: border-box;
  padding: 0.1rem;
}

.icon-img {
  display: block;
  width: 60%;
  margin: 0 auto;
  height: 80%;
}

.icon-desc {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0.44rem;
  line-height: 0.44rem;
  font-color: $darkTextColor;
  text-align: center;
  ellipsis();
}
</style>
